package com.lb.utils;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * @version 1.0
 * @Author: Edward
 * @Date: 2021/5/12 18:13
 * @Description:
 */
public class AUtils {
    public static void combinationUtil(int arr[], int data[], int start, int end, int index, int r, List<String> res)
    {
        if (index == r)
        {
            for (int j=0; j<r; j++) {
//                System.out.print(data[j]+" ");
                res.add(data[j]+" ");
            }
            System.out.println("");
            return;
        }

        for (int i=start; i<=end && end-i+1 >= r-index; i++)
        {
            data[index] = arr[i];
            combinationUtil(arr, data, i+1, end, index+1, r ,res);
        }
    }

    public static void main (String[] args) {
        int arr[] = {1, 2, 3, 4, 5};
        int r = 3;
        int n = arr.length;
        int data[]=new int[r];
        int start=0,end=n-1,index=0;
        List<String> res = Lists.newArrayList();
        combinationUtil(arr, data, start, end, index, r, res);
        System.out.println(res);
    }
}
